﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.MarketUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import Events.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Transactions.*;
    import Classes.util.*;
    import Classes.sim.*;
    import flash.filters.*;
    import org.aswing.geom.*;
    import ZLocalization.*;
    import Display.*;
    import GameMode.*;
    import flash.text.*;
    import Classes.inventory.*;
    import Modules.stats.experiments.*;
    import Display.aswingui.*;
    import L10n.*;
    import com.zynga.skelly.util.*;

    public class MarketCell extends DataItemCell implements IPlayerStateObserver, IGameWorldStateObserver {

        protected static const REQUIRED_WIDTH:int = 78;
        protected static const REQUIRED_HEIGHT:int = 30;
        protected static const MARKET_CELL_WIDTH:int = 88;

        private static var unlockCellsList:Array = new Array();
        private static var lockedCellsList:Array = new Array();

        private var m_amountNeeded:int;
        protected var m_itemCost:JLabel;
        protected var m_bgDec:MarginBackground;
        protected var m_currencyIcon:JPanel;
        protected var m_setIcon:JPanel;
        protected var m_alignmentContainer:JPanel;
        protected var m_itemIconPane:JPanel;
        protected var m_content:DisplayObject;
        protected var m_bgOver:DisplayObject;
        protected var m_swappedBG:DisplayObject;
        protected var m_itemLocked:Boolean;
        protected var m_curBGAsset:DisplayObject;
        protected var m_setIconLoader:Loader;
        protected var m_purchaseButton:JButton;
        protected var m_limitedTimePane:JPanel;
        protected var m_timeLeft:JTextField;
        protected var m_reqText:TextField;
        private var m_secondsLeft:Number;
        protected var m_bDisabled:Boolean = false;
        protected var m_buyable:Boolean = true;
        private var m_timerLabel:JLabel;
        protected var m_assetDict:Dictionary;

        public function MarketCell(_arg1:LayoutManager=null){
            var _local2:LayoutManager = _arg1;
            if (_local2 == null){
                _local2 = new SoftBoxLayout(SoftBoxLayout.Y_AXIS, -2, SoftBoxLayout.CENTER);
            };
            this.m_assetDict = Catalog.assetDict;
            super(_local2);
            Global.player.addObserver(this);
            Global.world.addObserver(this);
        }
        public static function refreshUnlockedCells(_arg1:String):void{
            var _local2 = -1;
            var _local3:int;
            while (_local3 < unlockCellsList.length) {
                if (unlockCellsList[_local3].m_item.name == _arg1){
                    _local2 = _local3;
                };
                _local3++;
            };
            if (_local2 > -1){
                unlockCellsList[_local2].killListeners();
                unlockCellsList[_local2].removeAll();
                if (unlockCellsList[_local2].m_itemIcon){
                    unlockCellsList[_local2].m_itemIcon.alpha = 1;
                };
                unlockCellsList[_local2].buildCell();
                unlockCellsList[_local2].initializeCell();
                unlockCellsList.splice(_local2);
            };
        }
        public static function addLockCell(_arg1:MarketCell):void{
            lockedCellsList.push(_arg1);
        }
        public static function reLockCells(_arg1:String):void{
            var _local2 = -1;
            var _local3:int;
            while (_local3 < lockedCellsList.length) {
                if (lockedCellsList[_local3].m_item.name == _arg1){
                    _local2 = _local3;
                };
                _local3++;
            };
            if (_local2 > -1){
                lockedCellsList[_local2].killListeners();
                lockedCellsList[_local2].removeAll();
                if (lockedCellsList[_local2].m_itemIcon){
                    lockedCellsList[_local2].m_itemIcon.alpha = 1;
                };
                lockedCellsList[_local2].buildCell();
                lockedCellsList[_local2].initializeCell();
                lockedCellsList.splice(_local2);
            };
        }
        public static function makeRequiredSprite(_arg1:Item, _arg2:DisplayObject):Sprite{
            var _local5:DisplayObject;
            var _local6:TextFormat;
            var _local10:TextFormat;
            var _local11:TextFormat;
            var _local3:String = _arg1.unlock;
            var _local4:Sprite = new Sprite();
            var _local7:TextField = new TextField();
            var _local8:TextField = new TextField();
            var _local9:TextField = new TextField();
            var _local12:Boolean = _arg1.isEmptyLot;
            if (_local12){
                if (!BuyLogic.isAtMaxFranchiseCount()){
                    _local3 = Item.UNLOCK_NEIGHBOR;
                };
            };
            switch (_local3){
                case Item.UNLOCK_NEIGHBOR:
                    _local5 = (new EmbeddedArt.mkt_btn_green() as DisplayObject);
                    break;
                case Item.UNLOCK_QUEST_AND_NEIGHBOR:
                    if (_arg1.requiredQuestFlag.length > 0){
                        if (!Global.questManager.isFlagReached(_arg1.requiredQuestFlag)){
                            _local5 = _arg2;
                        } else {
                            if (!Global.player.checkNeighbors(_arg1.requiredNeighbors)){
                                _local5 = (new EmbeddedArt.mkt_btn_green() as DisplayObject);
                            };
                        };
                    } else {
                        _local5 = (new EmbeddedArt.mkt_btn_green() as DisplayObject);
                    };
                    break;
                default:
                    _local5 = _arg2;
            };
            if (_local5){
                _local5.width = REQUIRED_WIDTH;
                _local5.height = REQUIRED_HEIGHT;
                _local5.y = 3;
                _local4.addChild(_local5);
            };
            var _local13:Object = BuyLogic.getUnlockText(_arg1);
            _local7 = new TextField();
            _local7.text = _local13.requires;
            _local7.width = REQUIRED_WIDTH;
            _local7.height = 20;
            _local4.addChild(_local7);
            _local7.y = 1;
            _local8 = new TextField();
            _local8.text = _local13.line1;
            _local8.width = REQUIRED_WIDTH;
            _local8.height = 20;
            _local8.autoSize = TextFieldAutoSize.CENTER;
            _local8.embedFonts = true;
            _local8.selectable = false;
            _local8.multiline = true;
            _local8.wordWrap = true;
            _local4.addChild(_local8);
            _local8.y = 13;
            if (_local8.length > 12){
                if (_local5){
                    _local5.height = 40;
                };
            };
            _local11 = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, 16773933, null, null, null, null, null, TextFormatAlign.CENTER);
            _local10 = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, 0xFFFFFF, null, null, null, null, null, TextFormatAlign.CENTER);
            _local6 = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, 0xFFFFFF, null, null, null, null, null, TextFormatAlign.CENTER);
            _local7.antiAliasType = AntiAliasType.ADVANCED;
            _local7.embedFonts = true;
            _local7.selectable = false;
            _local7.setTextFormat(_local6);
            if (_local3 == Item.UNLOCK_NEIGHBOR){
                _local7.filters = [new DropShadowFilter(1, 90, 0, 0.2, 1, 1, 3, 1), new GlowFilter(0, 0.2, 2, 2, 10)];
            };
            if (_local3 == Item.UNLOCK_QUEST_AND_NEIGHBOR){
                if (Global.questManager.isFlagReached(_arg1.requiredQuestFlag)){
                    _local7.filters = [new DropShadowFilter(1, 90, 0, 0.2, 1, 1, 3, 1), new GlowFilter(0, 0.2, 2, 2, 10)];
                    _local8.setTextFormat(_local10);
                    _local8.filters = [new DropShadowFilter(1, 90, 0, 0.2, 1, 1, 3, 1), new GlowFilter(0, 0.2, 2, 2, 10)];
                } else {
                    _local8.setTextFormat(_local11);
                };
                return (_local4);
            };
            if (_local3 == Item.UNLOCK_NEIGHBOR){
                _local8.setTextFormat(_local10);
                _local8.filters = [new DropShadowFilter(1, 90, 0, 0.2, 1, 1, 3, 1), new GlowFilter(0, 0.2, 2, 2, 10)];
            } else {
                _local8.setTextFormat(_local11);
            };
            if (_arg1.unlock == Item.UNLOCK_OLD_QUEST_OR_PURCHASE){
                _local4.visible = false;
            };
            return (_local4);
        }

        public function setAssetDict(_arg1:Dictionary):void{
            this.m_assetDict = _arg1;
        }
        override public function setCellValue(_arg1):void{
            var _local3:Set;
            _arg1 = (_arg1 as Object);
            m_item = _arg1;
            this.m_amountNeeded = m_item.cost;
            var _local2:String = Global.gameSettings.getImageByName(m_item.name, m_item.iconImageName);
            if (_local2 != null){
                _local3 = Global.gameSettings.getItemByName(m_item.name).getSet();
                if (_local3){
                    this.m_setIconLoader = LoadingManager.load(_local3.getIcon(), this.onSetIconLoad, LoadingManager.PRIORITY_HIGH);
                } else {
                    this.m_setIconLoader = null;
                };
                m_loader = LoadingManager.load(_local2, onIconLoad, LoadingManager.PRIORITY_HIGH);
            };
            this.buildCell();
        }
        public function setBuyable(_arg1:Boolean):void{
            if (this.m_buyable != _arg1){
                this.m_buyable = _arg1;
                removeAll();
                this.buildCell();
            };
        }
        protected function buildCell():void{
            var _local1:DisplayObject;
            if ((((((m_item.localizedName == ZLoc.t("Items", "supply_all_business_friendlyName"))) || ((m_item.localizedName == ZLoc.t("Items", "mark_all_business_ready_friendlyName"))))) || ((m_item.localizedName == ZLoc.t("Items", "instant_ready_crop_friendlyName"))))){
                this.buildInstantReadyCell();
                return;
            };
            this.m_alignmentContainer = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.m_itemLocked = BuyLogic.isLocked(m_item);
            if (((m_item.startDate) && (this.m_assetDict.hasOwnProperty("card_limited_item")))){
                _local1 = (new (this.m_assetDict["card_limited_item"])() as DisplayObject);
            } else {
                _local1 = (new (this.m_assetDict["card_available_unselected"])() as DisplayObject);
            };
            this.m_content = _local1;
            if (((((((!(BuyLogic.franchiseCheck(m_item))) && (Global.isVisiting()))) || (((!(Global.isVisiting())) && (!(BuyLogic.lotSiteCheck(this.m_item))))))) || (((!(Global.isVisiting())) && (BuyLogic.maxReceivedFranchisesCheck(this.m_item)))))){
                this.m_content.alpha = 0.7;
            } else {
                if ((((Global.player.gold < m_item.cost)) || (this.m_itemLocked))){
                    this.m_content.alpha = 0.7;
                };
            };
            if (((m_item.startDate) && (this.m_assetDict.hasOwnProperty("card_limited_item")))){
                this.m_bgOver = (new (this.m_assetDict["card_limited_item"])() as DisplayObject);
            } else {
                this.m_bgOver = (new (this.m_assetDict["card_available_selected"])() as DisplayObject);
            };
            ASwingHelper.setSizedBackground(this.m_alignmentContainer, this.m_content);
            this.m_alignmentContainer.setPreferredWidth(this.m_content.width);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.m_itemIconPane = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local3:JLabel = ASwingHelper.makeLabel(ZLoc.t("Dialogs", "Loading"), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 16, EmbeddedArt.darkBlueTextColor, JLabel.CENTER);
            var _local4:JPanel = ASwingHelper.centerElement(_local3);
            _local3.setPreferredWidth(this.m_content.width);
            _local4.setPreferredWidth(this.m_content.width);
            ASwingHelper.prepare(_local4);
            this.m_itemIconPane.append(_local4);
            _local2.append(this.m_itemIconPane);
            this.m_alignmentContainer.append(_local2);
            var _local5:JPanel = ASwingHelper.makeSoftBoxJPanel();
            this.append(this.m_alignmentContainer);
            if (((m_item.startDate) && (this.m_assetDict.hasOwnProperty("card_limited_counter")))){
                this.addCountdownTimer(this, MARKET_CELL_WIDTH);
            };
            this.append(ASwingHelper.verticalStrut(6));
            var _local6:Boolean = m_item.isEmptyLot;
            if (this.m_buyable){
                this.setupPurchaseButton();
                if (this.m_purchaseButton != null){
                    this.m_currencyIcon = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
                    this.m_currencyIcon.append(this.m_purchaseButton);
                    this.append(this.m_currencyIcon);
                };
                this.addEventListener(MouseEvent.ROLL_OVER, this.switchBG, false, 0, true);
                this.addEventListener(MouseEvent.ROLL_OUT, this.revertBG, false, 0, true);
                if (((_local6) && (this.m_itemLocked))){
                    if (!BuyLogic.isAtMaxFranchiseCount()){
                        this.addEventListener(MouseEvent.CLICK, this.unlockorBuyForEmptyLot, false, 0, true);
                    };
                } else {
                    if (((this.m_itemLocked) && ((m_item.unlock == Item.UNLOCK_NEIGHBOR)))){
                        this.addEventListener(MouseEvent.CLICK, this.unlockNeighbors, false, 0, true);
                    } else {
                        if (((this.m_itemLocked) && ((m_item.unlock == Item.UNLOCK_QUEST_AND_NEIGHBOR)))){
                            if (m_item.requiredQuestFlag.length > 0){
                                if (Global.questManager.isFlagReached(m_item.requiredQuestFlag)){
                                    if (Global.player.m_licenses[this.m_item.name] == 1){
                                        this.addEventListener(MouseEvent.CLICK, this.buyItem, false, 0, true);
                                    } else {
                                        this.addEventListener(MouseEvent.CLICK, this.unlockorBuyNeighbors, false, 0, true);
                                    };
                                } else {
                                    this.addEventListener(MouseEvent.CLICK, this.buyItem, false, 0, true);
                                };
                            } else {
                                this.addEventListener(MouseEvent.CLICK, this.unlockNeighbors, false, 0, true);
                            };
                        } else {
                            this.addEventListener(MouseEvent.CLICK, this.buyItem, false, 0, true);
                        };
                    };
                };
            } else {
                this.append(ASwingHelper.verticalStrut(20));
                this.killListeners();
            };
            ASwingHelper.prepare(this);
        }
        protected function buildInstantReadyCell():void{
            var _local9:AssetIcon;
            var _local10:Number;
            var _local1:int = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_INSTANT_READY_LINK_TEST);
            var _local2:int;
            var _local3:int = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_INSTANT_READY_COST);
            if (_local3 == 2){
                _local2 = 2;
            } else {
                if (_local3 == 3){
                    _local2 = 10;
                } else {
                    if (_local3 == 4){
                        _local2 = 20;
                    } else {
                        if (_local3 == 5){
                            _local2 = 50;
                        } else {
                            _local2 = 2;
                        };
                    };
                };
            };
            if (m_item.cash > 0){
            };
            this.m_alignmentContainer = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.m_itemLocked = BuyLogic.isLocked(m_item);
            var _local4:DisplayObject = (new (this.m_assetDict["card_available_unselected"])() as DisplayObject);
            this.m_content = _local4;
            if (((((((!(BuyLogic.franchiseCheck(m_item))) && (Global.isVisiting()))) || (((!(Global.isVisiting())) && (!(BuyLogic.lotSiteCheck(this.m_item))))))) || (((!(Global.isVisiting())) && (BuyLogic.maxReceivedFranchisesCheck(this.m_item)))))){
                this.m_content.alpha = 0.7;
            } else {
                if ((((Global.player.gold < m_item.cost)) || (this.m_itemLocked))){
                    this.m_content.alpha = 0.7;
                };
            };
            if (((m_item.startDate) && (this.m_assetDict.hasOwnProperty("card_limited_item")))){
                this.m_bgOver = (new (this.m_assetDict["card_limited_item"])() as DisplayObject);
            } else {
                this.m_bgOver = (new (this.m_assetDict["card_available_selected"])() as DisplayObject);
            };
            ASwingHelper.setSizedBackground(this.m_alignmentContainer, this.m_content);
            this.m_alignmentContainer.setPreferredWidth(this.m_content.width);
            var _local5:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.m_itemIconPane = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local6:JLabel = ASwingHelper.makeLabel(ZLoc.t("Dialogs", "Loading"), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 16, EmbeddedArt.darkBlueTextColor, JLabel.CENTER);
            var _local7:JPanel = ASwingHelper.centerElement(_local6);
            _local6.setPreferredWidth(this.m_content.width);
            _local7.setPreferredWidth(this.m_content.width);
            ASwingHelper.prepare(_local7);
            this.m_itemIconPane.append(_local7);
            _local5.append(this.m_itemIconPane);
            this.m_alignmentContainer.append(_local5);
            var _local8:JPanel = ASwingHelper.makeSoftBoxJPanel();
            this.append(this.m_alignmentContainer);
            this.append(ASwingHelper.verticalStrut(6));
            if (this.m_buyable){
                _local10 = _local2;
                if (((!(Global.isVisiting())) && (this.m_itemLocked))){
                    this.m_purchaseButton = this.createPurchaseButton(_local10);
                    this.m_bDisabled = true;
                    this.m_purchaseButton.setEnabled(false);
                } else {
                    if (((Global.isVisiting()) && (!(BuyLogic.franchiseCheck(m_item))))){
                        _local9 = new AssetIcon(new (this.m_assetDict["icon_coins"])());
                        this.m_purchaseButton = new CustomButton(".", _local9, "CoinsButtonUI");
                        this.m_purchaseButton.alpha = 0;
                    } else {
                        if (_local2 > 0){
                            _local9 = new AssetIcon(new (this.m_assetDict["icon_cash"])());
                            this.m_purchaseButton = new CustomButton(String(_local10), _local9, "CashButtonUI");
                        } else {
                            if (Global.player.gold < _local10){
                                this.m_purchaseButton = this.createPurchaseButton(_local10);
                                this.m_bDisabled = true;
                                this.m_purchaseButton.setEnabled(false);
                            } else {
                                if (((((!(Global.isVisiting())) && (!(BuyLogic.lotSiteCheck(this.m_item))))) || (((!(Global.isVisiting())) && (BuyLogic.maxReceivedFranchisesCheck(this.m_item)))))){
                                    _local9 = new AssetIcon(new (this.m_assetDict["icon_coins"])());
                                    this.m_purchaseButton = new CustomButton(".", _local9, "CoinsButtonUI");
                                    this.m_purchaseButton.alpha = 0;
                                } else {
                                    this.m_purchaseButton = this.createPurchaseButton(_local10);
                                    this.m_purchaseButton.setEnabled(true);
                                };
                            };
                        };
                    };
                };
                if (this.m_purchaseButton != null){
                    this.m_currencyIcon = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
                    this.m_currencyIcon.append(this.m_purchaseButton);
                    this.append(this.m_currencyIcon);
                };
                this.addEventListener(MouseEvent.ROLL_OVER, this.switchBG, false, 0, true);
                this.addEventListener(MouseEvent.ROLL_OUT, this.revertBG, false, 0, true);
                if (((this.m_itemLocked) && ((m_item.unlock == Item.UNLOCK_NEIGHBOR)))){
                    this.addEventListener(MouseEvent.CLICK, this.unlockNeighbors, false, 0, true);
                } else {
                    if (((this.m_itemLocked) && ((m_item.unlock == Item.UNLOCK_QUEST_AND_NEIGHBOR)))){
                        if (m_item.requiredQuestFlag.length > 0){
                            if (Global.questManager.isFlagReached(m_item.requiredQuestFlag)){
                                if (Global.player.m_licenses[this.m_item.name] == 1){
                                    this.addEventListener(MouseEvent.CLICK, this.buyItem, false, 0, true);
                                } else {
                                    this.addEventListener(MouseEvent.CLICK, this.unlockorBuyNeighbors, false, 0, true);
                                };
                            } else {
                                this.addEventListener(MouseEvent.CLICK, this.buyItem, false, 0, true);
                            };
                        } else {
                            this.addEventListener(MouseEvent.CLICK, this.unlockNeighbors, false, 0, true);
                        };
                    } else {
                        this.addEventListener(MouseEvent.CLICK, this.buyItem, false, 0, true);
                    };
                };
            } else {
                this.append(ASwingHelper.verticalStrut(20));
                this.killListeners();
            };
            ASwingHelper.prepare(this);
        }
        protected function setupPurchaseButton():void{
            var _local1:AssetIcon;
            var _local2:Number = m_item.GetItemSalePrice();
            if (((!(Global.isVisiting())) && (this.m_itemLocked))){
                this.m_purchaseButton = this.createPurchaseButton(_local2);
                this.m_bDisabled = true;
                this.m_purchaseButton.setEnabled(false);
            } else {
                if (((Global.isVisiting()) && (!(BuyLogic.franchiseCheck(m_item))))){
                    _local1 = new AssetIcon(new (this.m_assetDict["icon_coins"])());
                    this.m_purchaseButton = new CustomButton(".", _local1, "CoinsButtonUI");
                    this.m_purchaseButton.alpha = 0;
                } else {
                    if (m_item.goods > 0){
                        _local1 = new AssetIcon(new (this.m_assetDict["icon_goods"])());
                        this.m_purchaseButton = new CustomButton(String(_local2), _local1, "CoinsButtonUI");
                        if (_local2 > Global.player.commodities.getCount(Commodities.GOODS_COMMODITY)){
                            this.m_bDisabled = true;
                            this.m_purchaseButton.setEnabled(false);
                        };
                    } else {
                        if (m_item.fbc > 0){
                            this.m_purchaseButton = new CustomButton(ZLoc.t("Dialogs", "Buy"), _local1, "CashButtonUI");
                            this.m_purchaseButton.setMargin(new Insets(1, 5, 1, 5));
                        } else {
                            if (m_item.cash > 0){
                                _local1 = new AssetIcon(new (this.m_assetDict["icon_cash"])());
                                this.m_purchaseButton = new CustomButton(String(_local2), _local1, "CashButtonUI");
                            } else {
                                if (Global.player.gold < _local2){
                                    this.m_purchaseButton = this.createPurchaseButton(_local2);
                                    this.m_bDisabled = true;
                                    this.m_purchaseButton.setEnabled(false);
                                } else {
                                    if (((((!(Global.isVisiting())) && (!(BuyLogic.lotSiteCheck(this.m_item))))) || (((!(Global.isVisiting())) && (BuyLogic.maxReceivedFranchisesCheck(this.m_item)))))){
                                        _local1 = new AssetIcon(new (this.m_assetDict["icon_coins"])());
                                        this.m_purchaseButton = new CustomButton(".", _local1, "CoinsButtonUI");
                                        this.m_purchaseButton.alpha = 0;
                                    } else {
                                        this.m_purchaseButton = this.createPurchaseButton(_local2);
                                        this.m_purchaseButton.setEnabled(true);
                                    };
                                };
                            };
                        };
                    };
                };
            };
        }
        private function createPurchaseButton(_arg1:int):JButton{
            var _local3:JButton;
            var _local2:AssetIcon = new AssetIcon(new (this.m_assetDict["icon_coins"])());
            if (String(_arg1).length > 5){
                _local3 = new CustomButton(String(_arg1), _local2, "CoinsSmallButtonUI");
            } else {
                _local3 = new CustomButton(String(_arg1), _local2, "CoinsButtonUI");
            };
            return (_local3);
        }
        protected function killListeners():void{
            if (this.hasEventListener(MouseEvent.CLICK)){
                this.removeEventListener(MouseEvent.CLICK, this.buyItem);
                this.removeEventListener(MouseEvent.CLICK, this.unlockNeighbors);
                this.removeEventListener(MouseEvent.CLICK, this.unlockorBuyForEmptyLot);
                this.removeEventListener(MouseEvent.CLICK, this.unlockorBuyNeighbors);
            };
            if (this.hasEventListener(MouseEvent.ROLL_OVER)){
                this.removeEventListener(MouseEvent.ROLL_OVER, this.switchBG);
            };
            if (this.hasEventListener(MouseEvent.ROLL_OUT)){
                this.removeEventListener(MouseEvent.ROLL_OUT, this.revertBG);
            };
        }
        public function performUpdate(_arg1:Boolean=false):void{
            var _local2:Boolean = BuyLogic.isLocked(m_item);
            var _local3:Boolean;
            var _local4:Boolean = m_item.isEmptyLot;
            if ((((m_item.unlock == Item.UNLOCK_PERMITS)) || ((_local2 == this.m_itemLocked)))){
                if (m_item.requiredQuestFlag.length > 0){
                    if (Global.questManager.isFlagReached(m_item.requiredQuestFlag)){
                        _local3 = true;
                    };
                };
            };
            if ((((m_item.unlock == Item.UNLOCK_QUEST_AND_LEVEL)) || ((_local2 == this.m_itemLocked)))){
                if (m_item.requiredQuestFlag.length > 0){
                    if (Global.questManager.isFlagReached(m_item.requiredQuestFlag)){
                        _local3 = true;
                    };
                };
            };
            if ((((m_item.unlock == Item.UNLOCK_QUEST_AND_NEIGHBOR)) || ((_local2 == this.m_itemLocked)))){
                if (m_item.requiredQuestFlag.length > 0){
                    if (Global.questManager.isFlagReached(m_item.requiredQuestFlag)){
                        _local3 = true;
                    };
                };
            };
            if (((((((_arg1) || (!((_local2 == this.m_itemLocked))))) || (_local3))) || (((_local4) && (_local2))))){
                this.killListeners();
                removeAll();
                if (m_itemIcon){
                    m_itemIcon.alpha = 1;
                };
                this.buildCell();
                this.initializeCell();
            };
            if (this.m_purchaseButton != null){
                if (((((((!(_local2)) && ((this.m_bDisabled == true)))) && ((Global.player.gold >= m_item.cost)))) && ((this.m_purchaseButton.getUIClassID() == "CoinsButtonUI")))){
                    this.m_purchaseButton.setEnabled(true);
                    this.m_bDisabled = false;
                } else {
                    if ((((((this.m_bDisabled == false)) && ((Global.player.gold < m_item.cost)))) && ((this.m_purchaseButton.getUIClassID() == "CoinsButtonUI")))){
                        this.m_purchaseButton.setEnabled(false);
                        this.m_bDisabled = true;
                    };
                };
            };
        }
        private function requestPermits(_arg1:GenericPopupEvent):void{
            if (_arg1.button != GenericDialogView.SKIP){
                return;
            };
            this.permitFeed();
        }
        private function permitFeed():void{
            var _local2:Boolean;
            var _local3:String;
            var _local4:GenericDialog;
            var _local1:String = Global.player.cityName;
            _local2 = Global.world.viralMgr.sendPermitsRequest(Global.player, _local1);
            if (!_local2){
                _local3 = ZLoc.t("Dialogs", "ExpansionThrottlingMessage");
                _local4 = new GenericDialog(_local3);
                UI.displayPopup(_local4);
            };
        }
        private function buyPermits(_arg1:GenericPopupEvent):void{
            var _local4:int;
            if (_arg1.button != GenericDialogView.YES){
                return;
            };
            var _local2:int = ExpansionManager.instance.getNextExpansionNumPermitPurchaseToComplete();
            var _local3:int = ExpansionManager.instance.getNextExpansionPermitCostToComplete();
            if (Global.player.cash >= _local3){
                if (!Global.player.inventory.isItemCountBelowInventoryLimit("permits", _local2)){
                    UI.displayInventoryMaxExceededDialog();
                    return;
                };
                _local4 = (Global.player.cash - _local3);
                if (_local4 < 0){
                    _local4 = 0;
                };
                Global.player.cash = _local4;
                Global.player.inventory.addItems("permits", _local2);
                unlockCellsList.push(this);
                GameTransactionManager.addTransaction(new TAcquirePermit(m_item.name));
                refreshUnlockedCells(m_item.name);
            } else {
                UI.displayImpulseBuyPopup(ImpulseBuy.TYPE_MARKET_CASH);
            };
        }
        private function confirmPurchase(_arg1:GenericPopupEvent):void{
            var _local2:Item;
            var _local3:String;
            var _local4:String;
            var _local5:MysteryCrateDialog;
            if (_arg1.button == GenericDialogView.YES){
                _local2 = Global.gameSettings.getItemByName(m_item.name);
                _local3 = ZLoc.t("Items", (m_item.name + "_friendlyName"));
                _local4 = ZLoc.t("Dialogs", "Mystery_Crate_anticipation", {item:_local3});
                _local5 = new MysteryCrateDialog(_local4, "mysteryCrateDialog", GenericDialogView.TYPE_CUSTOM_OK, null, "Mystery_Crate", _local2.iconRelative, true, GenericDialogView.ICON_POS_LEFT, "", null, ZLoc.t("Dialogs", "Mystery_Crate_ok"));
                UI.displayPopup(_local5, true);
                GameTransactionManager.addTransaction(new TBuyMysteryCrate(m_item, 1));
            };
        }
        private function unlockItem(_arg1:GenericPopupEvent):void{
            var _local2:int;
            var _local3:int;
            if (_arg1.button == GenericDialogView.YES){
                Global.player.m_licenses[m_item.name] = 1;
                _local2 = m_item.unlockCost;
                if (m_item.unlock == Item.UNLOCK_PERMITS){
                    _local2 = ExpansionManager.instance.getNextExpansionLockOverrideCost();
                };
                _local3 = (Global.player.cash - _local2);
                if (_local3 < 0){
                    _local3 = 0;
                };
                Global.player.cash = _local3;
                unlockCellsList.push(this);
                GameTransactionManager.addTransaction(new TAcquireLicense(m_item.name));
                refreshUnlockedCells(m_item.name);
            } else {
                if (_arg1.button == GenericDialogView.SHARE){
                    if (this[m_item.unlockShareFunc] != null){
                        var _local4 = this;
                        _local4[m_item.unlockShareFunc]();
                    };
                };
            };
        }
        private function runFranchiseMarketCellChecks():Boolean{
            if (!BuyLogic.franchiseCountLevelCheck(m_item)){
                UI.displayMessage(ZLoc.t("Dialogs", "MaxFranchisesCheck", {level:Global.franchiseManager.nextFranchiseUnlock}));
                return (false);
            };
            if (!BuyLogic.franchiseCheck(this.m_item)){
                UI.displayMessage(ZLoc.t("Dialogs", "FranchiseCheck"));
                return (false);
            };
            return (true);
        }
        private function unlockNeighbors(_arg1:MouseEvent):void{
            if (_arg1.target.name != "JButton"){
                FrameManager.showTray(((("invite.php?ref=market_click_neighbor_gated_item&action=unlockItem&name=" + m_item.name) + "&requiredNeighbors=") + m_item.requiredNeighbors));
            };
        }
        private function showNeighborMFS(_arg1:GenericPopupEvent):void{
            FrameManager.showTray(((("invite.php?ref=market_click_neighbor_gated_item&action=unlockItem&name=" + m_item.name) + "&requiredNeighbors=") + m_item.requiredNeighbors));
        }
        private function showEmptyLotNeighborMFS(_arg1:GenericPopupEvent):void{
            FrameManager.showTray(((("invite.php?ref=market_click_neighbor_gated_item&action=unlockItem&name=" + m_item.name) + "&requiredNeighbors=") + BuyLogic.getNeededNeighborCountForNextFranchise));
        }
        private function buyNeighbors(_arg1:GenericPopupEvent):void{
            var _local3:int;
            if (_arg1.button != GenericDialogView.YES){
                return;
            };
            var _local2:int = this.m_item.unlockCost;
            if (Global.player.cash >= _local2){
                _local3 = (Global.player.cash - _local2);
                if (_local3 < 0){
                    _local3 = 0;
                };
                Global.player.cash = _local3;
                Global.player.m_licenses[this.m_item.name] = 1;
                unlockCellsList.push(this);
                GameTransactionManager.addTransaction(new TAcquireLicense(m_item.name));
                this.removeEventListener(MouseEvent.CLICK, this.unlockorBuyNeighbors);
                refreshUnlockedCells(m_item.name);
            } else {
                UI.displayImpulseBuyPopup(ImpulseBuy.TYPE_MARKET_CASH);
            };
        }
        private function buyFranchiseUnlocks(_arg1:GenericPopupEvent):void{
            var _local3:int;
            if (_arg1.button != GenericDialogView.YES){
                return;
            };
            var _local2:int = BuyLogic.getNextFranchiseUnlockCost;
            if (Global.player.cash >= _local2){
                _local3 = (Global.player.cash - _local2);
                if (_local3 < 0){
                    _local3 = 0;
                };
                Global.player.cash = _local3;
                Global.player.franchiseUnlocksPurchased = (Global.player.franchiseUnlocksPurchased + 1);
                unlockCellsList.push(this);
                GameTransactionManager.addTransaction(new TAcquireFranchiseUnlock(m_item.name));
                this.removeEventListener(MouseEvent.CLICK, this.unlockorBuyForEmptyLot);
                refreshUnlockedCells(m_item.name);
            } else {
                UI.displayImpulseBuyPopup(ImpulseBuy.TYPE_MARKET_CASH);
            };
        }
        private function unlockorBuyNeighbors(_arg1:MouseEvent):void{
            UI.displayNeighborBuyPopup(this.m_item.requiredNeighbors, this.m_item.unlockCost, this.showNeighborMFS, this.buyNeighbors);
        }
        private function unlockorBuyForEmptyLot(_arg1:MouseEvent):void{
            UI.displayFranchiseUnlockBuyPopup(BuyLogic.getNeededNeighborCountForNextFranchise, BuyLogic.getNextFranchiseUnlockCost, this.showEmptyLotNeighborMFS, this.buyFranchiseUnlocks);
        }
        private function showCantBuyDialog():void{
            switch (m_item.unlock){
                case Item.UNLOCK_SEEN_FLAG:
                    UI.displayMessage(ZLoc.t("Collections", (m_item.requiredSeenFlag + "_hint")), GenericDialogView.TYPE_OK);
                    break;
                default:
                    UI.displayMessage(ZLoc.t("Quest", (m_item.requiredQuestFlag + "_hint")), GenericDialogView.TYPE_OK);
            };
        }
        private function buyItem(_arg1:MouseEvent):void{
            var cash_cost:* = 0;
            var instant_ready_cost:* = 0;
            var itemPrice:* = 0;
            var unlockGetCashHandler:* = null;
            var scopedItem:* = null;
            var cratePrice:* = 0;
            var e:* = _arg1;
            StatsManager.count("market", "buyItem", m_item.name, m_item.type, m_item.subtype);
            var is_instant_ready:* = false;
            var instant_ready_msg:* = null;
            if (m_item.localizedName == ZLoc.t("Items", "supply_all_business_friendlyName")){
                is_instant_ready = true;
                instant_ready_msg = ZLoc.t("Items", "supply_all_business_popup");
            };
            if (m_item.localizedName == ZLoc.t("Items", "mark_all_business_ready_friendlyName")){
                is_instant_ready = true;
                instant_ready_msg = ZLoc.t("Items", "mark_all_business_ready_popup");
            };
            if (m_item.localizedName == ZLoc.t("Items", "instant_ready_crop_friendlyName")){
                is_instant_ready = true;
                instant_ready_msg = ZLoc.t("Items", "instant_ready_crop_popup");
            };
            if (is_instant_ready){
                cash_cost = 0;
                instant_ready_cost = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_INSTANT_READY_COST);
                if (instant_ready_cost == 2){
                    cash_cost = 2;
                } else {
                    if (instant_ready_cost == 3){
                        cash_cost = 10;
                    } else {
                        if (instant_ready_cost == 4){
                            cash_cost = 20;
                        } else {
                            if (instant_ready_cost == 5){
                                cash_cost = 50;
                            } else {
                                cash_cost = 2;
                            };
                        };
                    };
                };
                UI.displayMessage(instant_ready_msg, GenericDialogView.TYPE_OK, function (_arg1:GenericPopupEvent):void{
                    if (_arg1.button == GenericDialogView.YES){
                        StatsManager.count("dialog", "link_test", m_item.name, "show", "", "", cash_cost);
                    };
                });
                return;
            };
            var buyOk:* = false;
            if (Global.isVisiting()){
                buyOk = this.runFranchiseMarketCellChecks();
            } else {
                if (this.m_itemLocked == true){
                    itemPrice = this.m_item.unlockCost;
                    buyOk = false;
                    if (m_item.unlock == Item.UNLOCK_PERMITS){
                        if (m_item.requiredQuestFlag.length > 0){
                            if (!Global.questManager.isFlagReached(m_item.requiredQuestFlag)){
                                this.showCantBuyDialog();
                                return;
                            };
                        };
                        itemPrice = (ExpansionManager.instance.hasEnoughPermits()) ? ExpansionManager.instance.getNextExpansionLockOverrideCost() : ExpansionManager.instance.getNextExpansionPermitCostToComplete();
                        switch (ExpansionManager.instance.getBehaviorExperimentVariant()){
                            case ExperimentDefinitions.NEW_EXPANSION_BEHAVIOR_ACTIVATED:
                                m_item.unlockCost = itemPrice;
                                unlockGetCashHandler = Curry.curry(function (_arg1:MarketCell, _arg2:GenericPopupEvent):void{
                                    if (_arg2.button == GenericDialogView.YES){
                                        UI.goToCashPage(_arg2);
                                    } else {
                                        if (_arg2.button == GenericDialogView.SHARE){
                                            if (_arg1[_arg1.m_item.unlockShareFunc] != null){
                                                var _local3 = _arg1;
                                                _local3[_arg1.m_item.unlockShareFunc]();
                                            };
                                        };
                                    };
                                }, this);
                                if (ExpansionManager.instance.hasEnoughPermits()){
                                    UI.displayItemUnlock(this.unlockItem, this.m_item, (Global.player.cash >= itemPrice), unlockGetCashHandler, !(ExpansionManager.instance.hasEnoughPermits()));
                                } else {
                                    UI.displayPermitBuyPopup(ExpansionManager.instance.getNextExpansionNumPermitPurchaseToComplete(), itemPrice, this.requestPermits, this.buyPermits);
                                };
                                break;
                            default:
                                UI.displayPermitBuyPopup(ExpansionManager.instance.getNextExpansionPermitRequirement(), itemPrice, this.requestPermits, this.buyPermits);
                        };
                        return;
                    };
                    if (BuyLogic.shouldShowCantBuyDialog(m_item)){
                        this.showCantBuyDialog();
                        return;
                    };
                    if (Global.player.cash >= itemPrice){
                        if (LocaleHelper.localSetting.sns.cash_enable){
                            UI.displayItemUnlock(this.unlockItem, this.m_item, true);
                        };
                    } else {
                        if (LocaleHelper.localSetting.sns.cash_enable){
                            UI.displayItemUnlock(this.unlockItem, this.m_item, false);
                        };
                    };
                } else {
                    if (!BuyLogic.lotSiteCheck(this.m_item)){
                        buyOk = false;
                        UI.displayMessage(ZLoc.t("Dialogs", "LotSiteCheck"));
                    } else {
                        if (BuyLogic.maxReceivedFranchisesCheck(this.m_item)){
                            buyOk = false;
                            UI.displayMessage(ZLoc.t("Dialogs", "MaxFranchisesDialogText"));
                        } else {
                            buyOk = true;
                        };
                    };
                };
            };
            if (buyOk){
                if (m_item.unlock == Item.UNLOCK_PERMITS){
                    GMExpand.setMarketCell(this);
                };
                scopedItem = m_item;
                if (m_item.type == "mystery_crate"){
                    cratePrice = m_item.cash;
                    if (Global.player.cash >= cratePrice){
                        UI.displayItemPurchaseConfirm(this.confirmPurchase, this.m_item, true);
                    } else {
                        UI.displayItemPurchaseConfirm(this.confirmPurchase, this.m_item, false);
                    };
                } else {
                    if ((((((((m_item.type == "plot_contract")) && ((Global.player.cash >= m_item.GetItemSalePrice())))) && ((m_item.GetItemSalePrice() > 0)))) && ((m_item.cash > 0)))){
                        if (m_item.name != "plot_blueberries"){
                            if (!LocaleHelper.localSetting.sns.cash_enable){
                                UI.displayMessage(ZLoc.t("Dialogs", "cash_cannot_use_message"));
                                return;
                            };
                            UI.displayMessage(ZLoc.t("Dialogs", "BuyCashQuestion", {
                                object:m_item.localizedName,
                                amount:String(m_item.GetItemSalePrice())
                            }), GenericDialogView.TYPE_YESNO, function (_arg1:GenericPopupEvent):void{
                                if (_arg1.button == GenericDialogView.YES){
                                    dispatchEvent(new DataItemEvent(DataItemEvent.MARKET_BUY, scopedItem, null, true));
                                };
                            });
                        } else {
                            UI.displayDonationMessage("BlueberriesDonation", "assets/dialogs/cityCare_blueberry.png", GenericDialogView.TYPE_OK, function (_arg1:GenericPopupEvent):void{
                                if (_arg1.button == GenericDialogView.YES){
                                    dispatchEvent(new DataItemEvent(DataItemEvent.MARKET_BUY, scopedItem, null, true));
                                };
                            }, "BlueberriesDonation", false, null, ZLoc.t("Dialogs", "BlueberriesDonation_title"), 0, m_item.cash);
                        };
                    } else {
                        dispatchEvent(new DataItemEvent(DataItemEvent.MARKET_BUY, this.m_item, null, true));
                    };
                };
            };
        }
        override protected function initializeCell():void{
            var _local2:DisplayObject;
            var _local3:TextFormat;
            var _local7:TextFormat;
            var _local8:TextFormat;
            var _local9:AssetPane;
            var _local11:Number;
            var _local15:Sprite;
            var _local16:TextField;
            var _local17:TextFormat;
            var _local18:String;
            var _local19:int;
            var _local20:int;
            var _local21:Sprite;
            var _local22:TextFormat;
            var _local23:String;
            var _local24:JPanel;
            var _local25:DisplayObject;
            var _local26:AssetPane;
            var _local1:Sprite = new Sprite();
            var _local4:TextField = new TextField();
            var _local5:TextField = new TextField();
            var _local6:TextField = new TextField();
            var _local10:Sprite = new Sprite();
            var _local12:Boolean;
            var _local13:Boolean = m_item.isEmptyLot;
            this.m_itemIconPane.removeAll();
            if (Global.isVisiting()){
                _local11 = this.m_content.height;
                if (m_itemIcon){
                    _local10.addChild(m_itemIcon);
                };
                m_itemIcon.alpha = 1;
                _local9 = new AssetPane(_local10);
                this.m_itemIconPane.append(_local9);
                this.addFranchiseSaleSticker();
            } else {
                if ((((this.m_itemLocked == true)) && (!(_local13)))){
                    _local11 = this.m_content.height;
                    if (m_itemIcon){
                        _local10.addChild(m_itemIcon);
                        m_itemIcon.y = ((90 - _local11) / 2);
                    };
                    _local15 = makeRequiredSprite(m_item, (new (this.m_assetDict["pop_lock"])() as DisplayObject));
                    _local10.addChild(_local15);
                    _local15.y = 0;
                    if (m_itemIcon){
                        m_itemIcon.alpha = 0.5;
                        if (_local15.width > m_itemIcon.width){
                            m_itemIcon.x = ((_local15.width - m_itemIcon.width) / 2);
                        } else {
                            _local15.x = ((m_itemIcon.width - _local15.width) / 2);
                        };
                        m_itemIcon.y = ((_local11 - m_itemIcon.height) / 2);
                    };
                    _local16 = new TextField();
                    _local17 = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 11, 542337, null, null, null, null, null, TextFormatAlign.CENTER);
                    _local16.antiAliasType = AntiAliasType.ADVANCED;
                    _local16.embedFonts = true;
                    _local16.selectable = false;
                    _local16.wordWrap = true;
                    _local16.multiline = true;
                    if ((((((((((m_item.unlock == Item.UNLOCK_PERMITS)) || ((m_item.unlock == Item.UNLOCK_QUEST_FLAG)))) || ((m_item.unlock == Item.UNLOCK_QUEST_AND_LEVEL)))) || ((m_item.unlock == Item.UNLOCK_QUEST_AND_NEIGHBOR)))) || ((m_item.unlock == Item.UNLOCK_SEEN_FLAG)))){
                        if (BuyLogic.hasUnlockedFlag(m_item)){
                            _local12 = false;
                        };
                    };
                    if (((((this.m_buyable) && (_local12))) && (!((m_item.unlock == Item.UNLOCK_NEIGHBOR))))){
                        _local16 = new TextField();
                        if (m_item.unlock == Item.UNLOCK_PERMITS){
                            if ((((m_item.requiredQuestFlag.length > 0)) && (!(Global.questManager.isFlagReached(m_item.requiredQuestFlag))))){
                            } else {
                                _local19 = ExpansionManager.instance.getBehaviorExperimentVariant();
                                _local20 = ExperimentDefinitions.NEW_EXPANSION_BEHAVIOR_ACTIVATED;
                                if (((!((_local19 == _local20))) || ((((_local19 == _local20)) && ((ExpansionManager.instance.getNextExpansionNumPermitPurchaseToComplete() <= 0)))))){
                                    _local18 = ZLoc.t("Dialogs", "UnlockEarly", {amount:String(ExpansionManager.instance.getNextExpansionLockOverrideCost())});
                                } else {
                                    _local18 = "";
                                };
                            };
                        } else {
                            _local18 = ZLoc.t("Dialogs", "UnlockEarly", {amount:m_item.unlockCost});
                        };
                        if (!LocaleHelper.localSetting.sns.cash_enable){
                            _local18 = "";
                        };
                        _local16.multiline = true;
                        _local16.wordWrap = true;
                        _local16.text = _local18;
                        _local16.setTextFormat(_local17);
                        _local16.width = Math.max(m_itemIcon.width, _local15.width);
                        _local16.height = 30;
                        _local10.addChild(_local16);
                        _local16.y = 62;
                        _local16.antiAliasType = AntiAliasType.ADVANCED;
                        _local16.embedFonts = true;
                        _local16.selectable = false;
                    };
                    _local9 = new AssetPane(_local10);
                    _local9.setPreferredHeight(90);
                    this.m_itemIconPane.append(_local9);
                } else {
                    if (((Global.isVisiting()) && ((this.m_item.localizedName == ZLoc.t("Items", "biz_lotsite_4x4_friendlyName"))))){
                        _local11 = this.m_content.height;
                        _local10.addChild(m_itemIcon);
                        m_itemIcon.alpha = 0.5;
                        _local2 = (new (this.m_assetDict["pop_lock"])() as DisplayObject);
                        _local10.addChild(_local2);
                        m_itemIcon.y = ((_local11 - m_itemIcon.height) / 2);
                        _local2.y = 3;
                        if (_local2.width > m_itemIcon.width){
                            m_itemIcon.x = ((_local2.width - m_itemIcon.width) / 2);
                        } else {
                            _local2.x = ((m_itemIcon.width - _local2.width) / 2);
                        };
                        _local16 = new TextField();
                        _local16.text = ZLoc.t("Dialogs", "UnlockEarly");
                        if (!LocaleHelper.localSetting.sns.cash_enable){
                            _local16.text = "";
                        };
                        _local16.width = Math.max(m_itemIcon.width, _local2.width);
                        _local16.height = 30;
                        _local10.addChild(_local16);
                        _local16.y = (_local11 - 28);
                        _local4 = new TextField();
                        _local4.text = ZLoc.t("Dialogs", "RequiresText");
                        _local4.width = _local2.width;
                        _local4.height = 20;
                        _local10.addChild(_local4);
                        _local4.y = 1;
                        _local5 = new TextField();
                        _local5.text = ZLoc.t("Dialogs", "BusinessZoneRestrictOverlay");
                        _local5.width = _local2.width;
                        _local5.height = 20;
                        _local10.addChild(_local5);
                        _local5.y = 13;
                        _local17 = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 11, 542337, null, null, null, null, null, TextFormatAlign.CENTER);
                        _local16.embedFonts = true;
                        _local16.selectable = false;
                        _local16.wordWrap = true;
                        _local16.multiline = true;
                        _local3 = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, 0xFFFFFF, null, null, null, null, null, TextFormatAlign.CENTER);
                        _local4.embedFonts = true;
                        _local4.selectable = false;
                        _local8 = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, 16773933, null, null, null, null, null, TextFormatAlign.CENTER);
                        _local5.embedFonts = true;
                        _local5.selectable = false;
                        _local16.setTextFormat(_local17);
                        _local4.setTextFormat(_local3);
                        _local5.setTextFormat(_local8);
                        if (_local2.width > m_itemIcon.width){
                            m_itemIcon.x = ((_local2.width - m_itemIcon.width) / 2);
                        } else {
                            _local5.x = (_local4.x = (_local2.x = ((m_itemIcon.width - _local2.width) / 2)));
                        };
                        _local9 = new AssetPane(_local10);
                        this.m_itemIconPane.append(_local9);
                    } else {
                        if (!BuyLogic.lotSiteCheck(this.m_item)){
                            _local11 = this.m_content.height;
                            if (m_itemIcon){
                                _local10.addChild(m_itemIcon);
                                m_itemIcon.y = ((90 - _local11) / 2);
                            };
                            _local21 = makeRequiredSprite(m_item, (new (this.m_assetDict["pop_lock"])() as DisplayObject));
                            _local10.addChild(_local21);
                            _local21.y = 0;
                            if (m_itemIcon){
                                m_itemIcon.alpha = 0.5;
                                if (_local21.width > m_itemIcon.width){
                                    m_itemIcon.x = ((_local21.width - m_itemIcon.width) / 2);
                                } else {
                                    _local21.x = ((m_itemIcon.width - _local21.width) / 2);
                                };
                                m_itemIcon.y = ((_local11 - m_itemIcon.height) / 2);
                            };
                            if (!BuyLogic.isAtMaxFranchiseCount()){
                                _local16 = new TextField();
                                _local22 = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 11, 542337, null, null, null, null, null, TextFormatAlign.CENTER);
                                _local23 = ZLoc.t("Dialogs", "UnlockEarly", {amount:BuyLogic.getNextFranchiseUnlockCost});
                                if (!LocaleHelper.localSetting.sns.cash_enable){
                                    _local23 = "";
                                };
                                _local16.multiline = true;
                                _local16.wordWrap = true;
                                _local16.text = _local23;
                                _local16.setTextFormat(_local22);
                                if (m_itemIcon == null){
                                    _local16.width = _local21.width;
                                } else {
                                    _local16.width = Math.max(m_itemIcon.width, _local21.width);
                                };
                                _local16.height = 30;
                                _local10.addChild(_local16);
                                _local16.y = 62;
                                _local16.antiAliasType = AntiAliasType.ADVANCED;
                                _local16.embedFonts = true;
                                _local16.selectable = false;
                            };
                            _local9 = new AssetPane(_local10);
                            _local9.setPreferredHeight(90);
                            this.m_itemIconPane.append(_local9);
                        } else {
                            if (Global.player.gold < this.m_item.cost){
                                m_itemIcon.alpha = 1;
                                _local9 = new AssetPane(m_itemIcon);
                                this.m_itemIconPane.append(_local9);
                                if (this.m_item.sale > 0){
                                    this.addSaleSticker();
                                };
                            } else {
                                if (m_item.name == "plot_lettuce"){
                                    _local24 = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT);
                                    _local25 = (new EmbeddedArt.hud_act_cvcarsbug() as DisplayObject);
                                    _local26 = new AssetPane(_local25);
                                    _local24.append(_local26);
                                    this.m_itemIconPane.append(_local24);
                                };
                                _local9 = new AssetPane(m_itemIcon);
                                this.m_itemIconPane.append(_local9);
                                if (this.m_item.sale > 0){
                                    this.addSaleSticker();
                                };
                            };
                        };
                    };
                };
            };
            ASwingHelper.prepare(this);
            ASwingHelper.prepare(this.m_itemIconPane);
            var _local14:Number = ((this.getWidth() - this.m_itemIconPane.getWidth()) / 2);
            ASwingHelper.setEasyBorder(this.m_itemIconPane, 0, _local14);
        }
        protected function addFranchiseSaleSticker():void{
            var _local1:Sprite;
            var _local2:DisplayObject;
            var _local3:TextField;
            var _local4:TextField;
            if (this.m_assetDict["saleSticker"] == null){
                return;
            };
            _local1 = new Sprite();
            _local2 = (new (this.m_assetDict["saleSticker"])() as DisplayObject);
            _local1.addChild(_local2);
            _local2.y = 3;
            _local3 = new TextField();
            _local3.text = (Global.gameSettings.getInt("franchiseDiscountPct").toString() + "%");
            _local3.selectable = false;
            _local3.mouseEnabled = false;
            _local3.width = _local2.width;
            _local3.height = 20;
            _local1.addChild(_local3);
            _local3.x = 0;
            _local3.y = 12;
            var _local5:TextFormat = new TextFormat();
            _local5.align = TextFormatAlign.CENTER;
            _local5.bold = true;
            _local5.color = 0xFFFFFF;
            _local3.setTextFormat(_local5);
            _local4 = new TextField();
            _local4.text = ZLoc.t("Dialogs", "Market_OFF");
            _local4.mouseEnabled = false;
            _local4.selectable = false;
            _local4.width = _local2.width;
            _local4.height = 20;
            _local1.addChild(_local4);
            _local4.x = 0;
            _local4.y = (_local3.y + 12);
            _local4.setTextFormat(_local5);
            this.addChild(_local1);
            _local1.x = (this.width - _local1.width);
            _local1.y = 0;
        }
        protected function addSaleSticker():void{
            var _local1:Sprite;
            var _local2:DisplayObject;
            if (this.m_assetDict["sale_tag"] == null){
                return;
            };
            _local1 = new Sprite();
            _local2 = (new (this.m_assetDict["sale_tag"])() as DisplayObject);
            _local1.addChild(_local2);
            _local2.y = 3;
            this.addChild(_local1);
            _local1.x = 0;
            _local1.y = 0;
        }
        public function onSetIconLoad(_arg1:Event):void{
            var _local2:AssetPane = new AssetPane(this.m_setIconLoader.content);
            this.m_setIcon.appendAll(_local2);
            ASwingHelper.prepare(this.m_setIcon);
        }
        public function removeListeners():void{
            this.removeEventListener(MouseEvent.ROLL_OVER, this.switchBG);
            this.removeEventListener(MouseEvent.ROLL_OUT, this.revertBG);
            this.removeEventListener(MouseEvent.CLICK, this.buyItem);
            this.removeEventListener(MouseEvent.CLICK, this.unlockNeighbors);
            this.removeEventListener(MouseEvent.CLICK, this.unlockorBuyForEmptyLot);
            this.removeEventListener(MouseEvent.CLICK, this.unlockorBuyNeighbors);
        }
        override public function removeFromContainer():void{
            super.removeFromContainer();
            Global.player.removeObserver(this);
            Global.world.removeObserver(this);
        }
        private function revertBG(_arg1:MouseEvent):void{
            dispatchEvent(new Event("turnOffToolTip", true));
            var _local2:MarginBackground = new MarginBackground(this.m_swappedBG, new Insets(0, 0, 0, 0));
            this.m_alignmentContainer.setBackgroundDecorator(_local2);
            ASwingHelper.prepare(this.m_alignmentContainer);
        }
        private function switchBG(_arg1:MouseEvent):void{
            var _local2:IntPoint = this.getGlobalLocation();
            var _local3:Point = new Point(_local2.x, _local2.y);
            dispatchEvent(new DataItemEvent(DataItemEvent.SHOW_TOOLTIP, this.m_item, _local3, true));
            var _local4:MarginBackground = new MarginBackground(this.m_bgOver, new Insets(0, 0, 0, 0));
            this.m_swappedBG = this.m_alignmentContainer.getBackgroundDecorator().getDisplay(this.m_alignmentContainer);
            this.m_alignmentContainer.setBackgroundDecorator(_local4);
            ASwingHelper.prepare(this.m_alignmentContainer);
        }
        private function onBuyClick(_arg1:MouseEvent):void{
            var _local2:int;
            if (((m_item.cash) && ((Global.player.cash >= m_item.cash)))){
                _local2 = this.getIndex(this.m_itemCost);
                this.removeAt(_local2);
                this.m_itemCost = null;
                this.m_itemCost = new JLabel(((Global.player.inventory.getItemCountByName(m_item.name).toString() + "/") + this.m_amountNeeded));
                this.m_itemCost.setForeground(new ASColor(0xFFFFFF, 1));
                this.m_itemCost.setFont(ASwingHelper.getBoldFont(14));
                this.insert(_local2, this.m_itemCost);
            } else {
                if (((m_item.fbc) && ((m_item.fbc > 0)))){
                    _local2 = this.getIndex(this.m_itemCost);
                    this.removeAt(_local2);
                    this.m_itemCost = null;
                    this.m_itemCost = new JLabel(ZLoc.t("Dialogs", "Buy"));
                    this.m_itemCost.setForeground(new ASColor(0xFFFFFF, 1));
                    this.m_itemCost.setFont(ASwingHelper.getBoldFont(14));
                    this.insert(_local2, this.m_itemCost);
                };
            };
        }
        private function addCountdownTimer(_arg1:JPanel, _arg2:Number):void{
            var _local8:LocalizationObjectToken;
            var _local9:Timer;
            var _local3:DisplayObject = (new (this.m_assetDict["card_limited_counter"])() as DisplayObject);
            var _local4:JPanel = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 0, SoftBoxLayout.CENTER));
            _local4.setBackgroundDecorator(new AssetBackground(_local3));
            _local4.setPreferredSize(new IntDimension(_arg2, (_local3.height + 1)));
            _local4.setMaximumSize(new IntDimension(_arg2, (_local3.height + 1)));
            _local4.setMinimumSize(new IntDimension(_arg2, (_local3.height + 1)));
            var _local5:Number = new Date().getTime();
            var _local6:int = (m_item.endDate - _local5);
            var _local7:Object = DateUtil.calculateTimeDifference(_local6);
            if (m_item.showTimer === false){
                this.m_timerLabel = ASwingHelper.makeLabel(ZLoc.t("Main", "LimitedEditionMarketCellText"), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, EmbeddedArt.whiteTextColor, JLabel.CENTER);
            } else {
                if (_local7.days > 0){
                    _local8 = ZLoc.tk("Main", "Day", "", _local7.days);
                    this.m_timerLabel = ASwingHelper.makeLabel(ZLoc.t("Main", "LimitedEditionMarketCellDayText", {
                        days:_local7.days,
                        day:_local8
                    }), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, EmbeddedArt.whiteTextColor, JLabel.CENTER);
                } else {
                    this.m_timerLabel = ASwingHelper.makeLabel("", EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, EmbeddedArt.whiteTextColor, JLabel.CENTER);
                    this.m_timerLabel.setPreferredWidth(_local3.width);
                    this.renderCountdownTimer(null);
                    _local9 = new Timer(100);
                    _local9.addEventListener(TimerEvent.TIMER, this.renderCountdownTimer);
                    _local9.start();
                };
            };
            _local4.append(this.m_timerLabel);
            _arg1.append(ASwingHelper.verticalStrut(-12));
            _arg1.append(_local4);
        }
        private function renderCountdownTimer(_arg1:TimerEvent):void{
            var _local2:Number = new Date().getTime();
            var _local3:int = (m_item.endDate - _local2);
            var _local4:Object = DateUtil.calculateTimeDifference(_local3);
            if (_local3 < 0){
                _local4.days = 0;
                _local4.hours = 0;
                _local4.minutes = 0;
                _local4.seconds = 0;
            };
            if (_local4.minutes < 10){
                _local4.minutes = ("0" + _local4.minutes);
            };
            if (_local4.seconds < 10){
                _local4.seconds = ("0" + _local4.seconds);
            };
            var _local5:String = ((((_local4.hours + ":") + _local4.minutes) + ":") + _local4.seconds);
            this.m_timerLabel.setText(_local5);
            this.m_timerLabel.repaint();
        }
        private function onAskClick(_arg1:MouseEvent):void{
        }
        public function energyChanged(_arg1:Number):void{
        }
        public function levelChanged(_arg1:int):void{
        }
        public function commodityChanged(_arg1:int, _arg2:String):void{
        }
        public function xpChanged(_arg1:int):void{
        }
        public function goldChanged(_arg1:int):void{
        }
        public function cashChanged(_arg1:int):void{
        }
        public function initialize():void{
        }
        public function cleanUp():void{
        }
        public function onGameLoaded(_arg1:Object):void{
        }
        public function onResourceChange(_arg1:MapResource, _arg2:Vector3, _arg3:Vector3):void{
        }

    }
}//package Display.MarketUI 
